package com.example.springcloud.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.example.springcloud.domain.Regions;
import com.example.springcloud.service.IRegionsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地区分类（如锦江区、成华区）Controller
 * 
 * @author hx
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/group_buy/regions")
@Api(tags = "地区管理")
public class RegionsController extends BaseController
{
    @Autowired
    private IRegionsService regionsService;

    /**
     * 查询地区分类（如锦江区、成华区）列表
     */
    @GetMapping("/list")
    @ApiOperation("查询地区列表 option2 ")
    public TableDataInfo list(Regions regions)
    {
        startPage();
        List<Regions> list = regionsService.selectRegionsList(regions);
        return getDataTable(list);
    }

    /**
     * 导出地区分类（如锦江区、成华区）列表
     */
    @PreAuthorize("@ss.hasPermi('group_buy:regions:export')")
    @Log(title = "地区分类（如锦江区、成华区）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Regions regions)
    {
        List<Regions> list = regionsService.selectRegionsList(regions);
        ExcelUtil<Regions> util = new ExcelUtil<Regions>(Regions.class);
        util.exportExcel(response, list, "地区分类（如锦江区、成华区）数据");
    }

    /**
     * 获取地区分类（如锦江区、成华区）详细信息
     */
    @PreAuthorize("@ss.hasPermi('group_buy:regions:query')")
    @GetMapping(value = "/{regionId}")
    public AjaxResult getInfo(@PathVariable("regionId") Long regionId)
    {
        return success(regionsService.selectRegionsByRegionId(regionId));
    }

    /**
     * 新增地区分类（如锦江区、成华区）
     */
    @PreAuthorize("@ss.hasPermi('group_buy:regions:add')")
    @Log(title = "地区分类（如锦江区、成华区）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Regions regions)
    {
        return toAjax(regionsService.insertRegions(regions));
    }

    /**
     * 修改地区分类（如锦江区、成华区）
     */
    @PreAuthorize("@ss.hasPermi('group_buy:regions:edit')")
    @Log(title = "地区分类（如锦江区、成华区）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Regions regions)
    {
        return toAjax(regionsService.updateRegions(regions));
    }

    /**
     * 删除地区分类（如锦江区、成华区）
     */
    @PreAuthorize("@ss.hasPermi('group_buy:regions:remove')")
    @Log(title = "地区分类（如锦江区、成华区）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{regionIds}")
    public AjaxResult remove(@PathVariable Long[] regionIds)
    {
        return toAjax(regionsService.deleteRegionsByRegionIds(regionIds));
    }
}
